#include "stdafx.h"
#include "_Title.h"
#include "_GraphLayout.h"


/*
*  @brief Constructor
*/
_Title::_Title(_GraphLayout& Layout):
    m_Layout(Layout)
{
    m_Size        = 30;
    m_Visible     = false;
    m_Color       = RGB(0xC0, 0xC0, 0xC0);
}

/*
*  @brief Destructor
*/
_Title::~_Title(void)
{
}

/*
*  @brief Draws the Title
*  @param BorderSize Size of the border
*/
void _Title::draw(_u32 BorderSize)
{
    // Draw to complete control window
    glViewport(0, 0, m_Layout.m_ControlRect.Width(), m_Layout.m_ControlRect.Height());
    // Set the coordinate system
    glLoadIdentity();
    gluOrtho2D(0, m_Layout.m_ControlRect.Width(), 0, m_Layout.m_ControlRect.Height());

    if(m_Visible)
    {
        // Fill title area
        glColor3i(GET_GLINT_R(m_Color), GET_GLINT_G(m_Color), GET_GLINT_B(m_Color));
        glRectd(BorderSize + 0,
                m_Layout.m_ControlRect.Height() - m_Size - BorderSize,
                m_Layout.m_ControlRect.Width() - BorderSize,
                m_Layout.m_ControlRect.Height() - BorderSize
               );
        // Draw the title string
        glColor3d(0, 0, 0);
        glRasterPos2d(60 + 0, m_Layout.m_ControlRect.Height() - m_Size + 8 - BorderSize);
        drawText(m_Title, OGL_DRAWABLE_FONT_ARIAL_15, 60, m_Layout.m_ControlRect.Height() - m_Size + 8 - BorderSize, 0, 0, 0);
    }
}


/*
*  @brief Sets the size of the Title
*  @param Size - new size in pixels
*/
void _Title::setSize(_u32 Size)
{
    m_Size = Size;
}

/*
*  @brief Returns the size of the Title
*  @returns Size in pixels
*/
_u32 _Title::getSize()
{
    if(m_Visible == false)
    {
        return 0;
    }
    else
    {
        return m_Size;
    }
}

/*
*  @brief Sets the margin from the left border of the title
*  @param Size - new margin in pixels
*/
void _Title::setMargin(_u32 Margin)
{
    m_MarginLeft = Margin;
}

/*
*  @brief Returns the margin from the left border
*  @returns margin in pixels
*/
_u32 _Title::getMargin()
{
    return m_MarginLeft;
}

/*
*  @brief Sets the visibility of the Title
*  @param Visible - New visibility
*/
void _Title::setVisible(bool Visible)
{
    m_Visible = Visible;
}

/*
*  @brief Returns if the graph is visible or not
*  @returns true or false
*/
bool _Title::isVisible()
{
    return m_Visible;
}

/*
*  @brief Sets the color of the Title
*  @param Color - New Title color
*/
void _Title::setColor(COLORREF Color)
{
    m_Color = Color;
}

/*
*  @brief Returns the color of the Title
*  @returns Color as RGB color reference
*/
COLORREF _Title::getColor()
{
    return m_Color;
}

/*
*  @brief The title string
*  @param Title - String
*/
void _Title::setTitle(CStringW Title)
{
    m_Title = Title;

    if(m_Title == L"")
    {
        m_Visible = false;
    }
    else
    {
        m_Visible = true;
    }
}

/*
*  @brief Returns the Titlestring
*  @returns Title as string
*/
CStringW& _Title::getTitle()
{
    return m_Title;
}
